package com.cancan.cloud.shop.filter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.HttpCookie;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.netty.ByteBufFlux;

import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 认证过滤器
 *
 * @author ZhouFufeng
 * @since 2020/3/12
 **/
@Slf4j
@Component
public class AuthRequestFilter extends BaseGlobalFilter implements GlobalFilter, Ordered {

    @Override
    public int getOrder() {
        return -3;
    }

    @Override
    public Mono<Void> doFilter(ServerWebExchange exchange, GatewayFilterChain chain) {
        log.info("不放行，进入下一个过滤器");
        String path = exchange.getRequest().getURI().getPath();
        log.info("进入全局过滤器，请求路径为：{}", path);
        // 编写任何你想要实现的逻辑，比如权限校验
        return chain.filter(exchange);
    }
}

